package work_pattern;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Constant {
    private static final String HOST = "47.108.48.236";
    private static final int PORT = 5672;
    private static final String VIRTUAL_HOST = "test";
    private static final String USER_NAME = "admin";
    private static final String PASSWORD = "admin";

    public static final String PUBLISH_EXCHANGE = "publish";
    public static final String PUBLISH_QUEUE_1 = "publish_queue_1";
    public static final String PUBLISH_QUEUE_2 = "publish_queue_2";

    public static final String ROUTING_EXCHANGE = "routing";
    public static final String ROUTING_QUEUE_1 = "routing_queue_1";
    public static final String ROUTING_QUEUE_2 = "routing_queue_2";
    public static final String ROUTING_KEY_1 = "routing_1";
    public static final String ROUTING_KEY_2 = "routing_2";
    public static final String ROUTING_KEY_3 = "routing_3";
    public static final String PUBLISH_CONFIRM_QUEUE = "publish.confirm.queue";
    public static final String RPC_QUEUE = "rpc_queue";

    /**
     * 创建 channel
     * @return
     * @throws IOException
     * @throws TimeoutException
     */
    public static Channel createChannel() throws IOException, TimeoutException {
        // 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        // 设置参数
        factory.setHost(HOST);
        factory.setPort(PORT);
        factory.setVirtualHost(VIRTUAL_HOST);
        factory.setUsername(USER_NAME);
        factory.setPassword(PASSWORD);
        // 创建连接
        Connection connection = factory.newConnection();
        // 创建 channel
        return connection.createChannel();
    }
}
